Ext.ns('TaxonTagger');
TaxonTagger.generalPanel = function(config){

	this.serverStore = new Ext.data.ArrayStore({
   		fields: ['id','server']   
    ,	data: [
					['gbif-lucene','GBIF Lucene']
				, ['gbif-tf','GBIF TaxonFinder']
				, ['ubio-tf','uBio TaxonFinder']
				, ['ubio-neti','uBio NetiNeti']
			]
	});
	
	this.nameServer = new Ext.form.ComboBox({
			store: this.serverStore
		,	scope: this	
		,	fieldLabel: this.flNameServer
		,	displayField: 'server'
		,	valueField: 'id'
		,	typeAhead: true
		,	editable: false
		,	mode: 'local'
		,	triggerAction: 'all'
		,	selectOnFocus: true
	});
	
	this.primaryCombo = new Ext.form.ComboBox({
			store: TaxonTagger.authorityStore
		,	scope: this
		,	fieldLabel: this.flPrimaryCombo	
		,	displayField: 'authority'
		,	valueField: 'id'
		,	typeAhead: true
		,	editable: false
		,	mode: 'local'
		,	triggerAction: 'all'
		,	selectOnFocus: true
	});	
	
	this.secondaryCombo = new Ext.form.ComboBox({
			store: TaxonTagger.authorityStore
		,	scope: this
		,	fieldLabel: this.flSecondaryCombo	
		,	displayField: 'authority'
		,	valueField: 'id'
		,	editable: false
		,	typeAhead: true
		,	mode: 'local'
		,	triggerAction: 'all'
		,	selectOnFocus: true
	});	
	
	Ext.apply(this, config, {
			labelWidth: 200
		,	padding: '5px'
		,	defaults: {
					width: '100%'
				,	anchor: '100%'
			}
		,	items: [
					this.nameServer
				,	this.primaryCombo
				,	this.secondaryCombo
				,	{
						xtype: 'checkbox'
					,	ref: 'checkLocal'	
					,	scope: this
					,	fieldLabel: this.flUseLocalStorage
					,	boxLabel: ''
					,	checked: true
				}
			]
		,	listeners: {
				render: this.loadStorage
			}	
	});

	TaxonTagger.generalPanel.superclass.constructor.call(this, config);

};

Ext.extend(TaxonTagger.generalPanel, Ext.FormPanel, {

	loadStorage: function(){
		var tConfig = Ext.decode(localStorage.getItem("settings")) || Config;
		this.checkLocal.setValue(tConfig["general"]["useStorage"]);
		this.nameServer.setValue(tConfig["general"]["nfServer"]);
		this.primaryCombo.setValue(tConfig["general"]["primary"]);
		this.secondaryCombo.setValue(tConfig["general"]["secondary"]);
	}

});